package com.oa.lms.apps.actions.limit;

import java.util.List;

import com.oa.lms.apps.actions.BasicAction;
import com.oa.lms.apps.business.limit.ILimitInfoService;
import com.oa.lms.apps.entity.limit.LimitInfoValue;
import com.oa.lms.apps.entity.user.UsersValue;


@SuppressWarnings("serial")
public class LimitInfoAction extends BasicAction {
	private ILimitInfoService limitService;
	
	private List<LimitInfoValue> parentList;
	private List<LimitInfoValue> childrenList;

	private String str;
     
	public String toLoad() throws Exception{
		UsersValue userInfo = (UsersValue) session.get("login_userInfo");
		int postId = userInfo.getUserInfo().getPostInfo().getPostId();
		str = "";
		parentList = limitService.queryByParentId(0, postId);
		if(parentList != null && parentList.size() != 0)
		for(int indexX = 0; indexX < parentList.size(); indexX++){
			
			str += "<table width='147'  border='0' align='center' cellpadding='0' cellspacing='0'><tr  onClick=show('"+indexX+"')  style='cursor:hand'><td height='23' background='images/main_34.gif'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='9%'>&nbsp;</td><td width='83%'><div align='center' class='STYLE5'>"+parentList.get(indexX).getLimitName()+"</div></td><td width='8%'>&nbsp;</td></tr></table></td></tr><tr><td valign='top'><div align='center'>";
			
			childrenList = limitService.queryByParentId(parentList.get(indexX).getLimitId(), postId);
			
			for(int indexY = 0; indexY < childrenList.size(); indexY++){
				
				str += "<table width='82%' border='0' id='"+indexX+"@"+indexY+"'  align='center' cellpadding='0' cellspacing='0'><tr><td height='38'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='33' height='28'><img src='images/main_46.gif' width='28' height='28'></td><td width='99'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td onClick=go('"+childrenList.get(indexY).getLimitUrl()+"') height='23' class='STYLE4' style='cursor:hand' onMouseOver='this.style.backgroundImage='url(images/tab_bg.gif)';this.style.borderStyle='solid';this.style.borderWidth='1';borderColor='#adb9c2'; 'onmouseout='this.style.backgroundImage='url()';this.style.borderStyle='none''>"+childrenList.get(indexY).getLimitName()+"</td></tr></table></td></tr></table></td></tr></table>";
			
			}
			str += "</div></td></tr></table>";
		}
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write(str);
		response.getWriter().close();
		
		return null;
	}


	public ILimitInfoService getLimitService() {
		return limitService;
	}

	public void setLimitService(ILimitInfoService limitService) {
		this.limitService = limitService;
	}

	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}
	
}